package com.sensePlusVR.adapter;

import java.util.List;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;

import com.sensePlusVR.bean.StoreItem;
import com.sensePlusVR.main.R;
import com.sensePlusVR.utils.MyLog;
/**
 * 
 * @author: Loren
 * @create: 2016-8-10下午2:53:56
 * @desc: My -->Setting -->Feedback -->Store adapter
 *
 */
public class StoreAdapter extends
		RecyclerView.Adapter<StoreAdapter.ViewHolders> implements
		OnClickListener {
	
	private static final String TAG = StoreAdapter.class.getSimpleName();
	private List<StoreItem> videoList;
	private OnRecyclerViewItemClickListener onItemClick;
	
	
	public StoreAdapter(List<StoreItem> videoList){
		this.videoList = videoList;
	}
	@Override
	public ViewHolders onCreateViewHolder(ViewGroup parent, int viewType) {
		 View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_setting_core_stroe_item,parent,false);
	     view.setOnClickListener(this);
	     return new ViewHolders(view);
	}
	
	@Override
	public void onBindViewHolder(ViewHolders holder, int position) {
		StoreItem item=videoList.get(position);
		MyLog.d(TAG, "list size : " + videoList.size());
		holder.setting_store_title.setText(item.getTitle());
        holder.setting_store_desc.setText(item.getDesc());
        holder.setting_store_distance.setText(item.getDistance());
        holder.itemView.setTag(item);
	}
	
	@Override
	public int getItemCount() {
		return videoList.size();
	}
	
	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public void onClick(View v) {
		 if(onItemClick!=null){
	            onItemClick.OnItemClick(v,(StoreItem) v.getTag());
	        }
	}
	
	class ViewHolders extends RecyclerView.ViewHolder {
		public TextView setting_store_title;
		public TextView setting_store_desc;
		public TextView setting_store_distance;

		public ViewHolders(View itemView) {
            super(itemView);
            setting_store_title = (TextView) itemView.findViewById(R.id.setting_store_title);
            setting_store_desc = (TextView) itemView.findViewById(R.id.setting_store_desc);
            setting_store_distance = (TextView) itemView.findViewById(R.id.setting_store_distance);
        }
	}
	
	  public void add(StoreItem item, int position) {
		  videoList.add(position, item);
	        notifyItemInserted(position);
	    }

	    public void remove(StoreItem item) {
	        int position = videoList.indexOf(item);
	        videoList.remove(position);
	        notifyItemRemoved(position);
	    }

	public void setOnRecyclerViewItemClickListener(
			OnRecyclerViewItemClickListener onItemClick) {
		this.onItemClick = onItemClick;
	}

	public interface OnRecyclerViewItemClickListener {
		public void OnItemClick(View view,StoreItem item);
	}


}
